#include "Unit.h"


Unit::Unit(void)
{
	GameComponent*  temp = new PositionalComponent();
	my_components.push_back(temp);

	temp = new ViewableComponent();
	my_components.push_back(temp);
	
	temp = new TouchableComponent();
	my_components.push_back(temp);
	
	temp = new MoveableComponent();
	my_components.push_back(temp);
}

Unit::Unit(char* fname)
{ 
	GameComponent*  temp;
	int num_components = 0;
	float tempF;
	AlphaVector tempV;
	string component_ID;
	string tempS;
	std::ifstream in (fname);
		if(!in)
		{
			std::cout<<"cannot open file "<< fname << std::endl;
		}
		else
		{
			std::cout <<"opening " << fname << "..." << std::endl;
			in >> num_components;
			for(int i = 0; i < num_components; i++)
			{
				in >> component_ID;
				if(component_ID  == "POSITIONAL")
				{
					in >> tempF;
					tempV.setX(tempF);
					in >> tempF;
					tempV.setZ(tempF);
					temp = new PositionalComponent(tempV);
					my_components.push_back(temp);
				}
				if(component_ID  == "MOVEABLE")
				{
					temp = new MoveableComponent();
					my_components.push_back(temp);
				}
				if(component_ID  == "VIEWABLE")
				{
					in >> tempS;
					temp = new ViewableComponent(tempS);
					my_components.push_back(temp);
				}
				if(component_ID  == "TOUCHABLE")
				{
					temp = new TouchableComponent();
					my_components.push_back(temp);
				}
			}
			in.close();
			std::cout << fname << " closed" << std::endl << std::endl;
		}
}


Unit::~Unit(void)
{
}


void Unit::updateMe(GameComponent* parent)
{
	
}
